<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>AJAX | Introduction</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/VUE/vue.html" />
    
    
    <link rel="prev" href="../../home/jQuery_j/5.jquery元素节点操作.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5"
        data-chapter-title="AJAX"
        data-filepath="home/AJAX/AJAX.md"
        data-basepath="../.."
        data-revision="Sat Nov 17 2018 12:52:35 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="home/HTML_h/html.html">
            
                
                    <a href="../../home/HTML_h/html.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        HTML
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="home/HTML_h/1.HTML概述和基本结构.html">
            
                
                    <a href="../../home/HTML_h/1.HTML概述和基本结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        HTML概述和基本结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="home/HTML_h/2.HTML中Head头.html">
            
                
                    <a href="../../home/HTML_h/2.HTML中Head头.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        HTML中Head头
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="home/HTML_h/3.HTML标题.html">
            
                
                    <a href="../../home/HTML_h/3.HTML标题.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        HTML标题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="home/HTML_h/4.HTML段落,换行,字符实体.html">
            
                
                    <a href="../../home/HTML_h/4.HTML段落,换行,字符实体.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        HTML段落,换行,字符实体
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="home/HTML_h/5.HTML块,含样式的标签.html">
            
                
                    <a href="../../home/HTML_h/5.HTML块,含样式的标签.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        HTML块,含样式的标签
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="home/HTML_h/6.HTML图片.html">
            
                
                    <a href="../../home/HTML_h/6.HTML图片.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        HTML图片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="home/HTML_h/7.HTML链接.html">
            
                
                    <a href="../../home/HTML_h/7.HTML链接.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        HTML链接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="home/HTML_h/8.HTML列表.html">
            
                
                    <a href="../../home/HTML_h/8.HTML列表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        HTML列表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="home/HTML_h/9.HTML表格.html">
            
                
                    <a href="../../home/HTML_h/9.HTML表格.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.9.</b>
                        
                        HTML表格
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="home/HTML_h/10.HTML表单.html">
            
                
                    <a href="../../home/HTML_h/10.HTML表单.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.10.</b>
                        
                        HTML表单
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="home/HTML_h/css.html">
            
            <span><b>2.</b> CSS</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/CSS_c/1.CSS基本语法.html">
            
                
                    <a href="../../home/CSS_c/1.CSS基本语法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        CSS基本语法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/CSS_c/2.CSS选择器.html">
            
                
                    <a href="../../home/CSS_c/2.CSS选择器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        CSS选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="home/CSS_c/3.CSS颜色,文本字体.html">
            
                
                    <a href="../../home/CSS_c/3.CSS颜色,文本字体.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        CSS颜色,文本字体
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="home/CSS_c/4.边框,背景,边距,溢出.html">
            
                
                    <a href="../../home/CSS_c/4.边框,背景,边距,溢出.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        边框,背景,边距,溢出
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="home/CSS_c/5.盒子.html">
            
                
                    <a href="../../home/CSS_c/5.盒子.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        盒子
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="home/CSS_c/6.元素,内联元素,内联块元素.html">
            
                
                    <a href="../../home/CSS_c/6.元素,内联元素,内联块元素.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        元素,内联元素,内联块元素
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="home/CSS_c/7.浮动.html">
            
                
                    <a href="../../home/CSS_c/7.浮动.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        浮动
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="home/CSS_c/8.定位.html">
            
                
                    <a href="../../home/CSS_c/8.定位.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        定位
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="home/JavaScript_j/JavaScript.html">
            
                
                    <a href="../../home/JavaScript_j/JavaScript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        JavaScript
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/JavaScript_j/1.js使用场景.html">
            
                
                    <a href="../../home/JavaScript_j/1.js使用场景.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        js使用场景
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/JavaScript_j/2.js变量.html">
            
                
                    <a href="../../home/JavaScript_j/2.js变量.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        js变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/JavaScript_j/3.js数据类型转换.html">
            
                
                    <a href="../../home/JavaScript_j/3.js数据类型转换.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        js数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/JavaScript_j/4.js运算符.html">
            
                
                    <a href="../../home/JavaScript_j/4.js运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        js运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="home/JavaScript_j/5.js流程控制.html">
            
                
                    <a href="../../home/JavaScript_j/5.js流程控制.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        js流程控制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="home/JavaScript_j/6.js循环.html">
            
                
                    <a href="../../home/JavaScript_j/6.js循环.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        js循环
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="home/JavaScript_j/7.js元素获取与操作.html">
            
                
                    <a href="../../home/JavaScript_j/7.js元素获取与操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        js元素获取与操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="home/JavaScript_j/8.js定时器.html">
            
                
                    <a href="../../home/JavaScript_j/8.js定时器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        js定时器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="home/JavaScript_j/9.js函数.html">
            
                
                    <a href="../../home/JavaScript_j/9.js函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        js函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="home/JavaScript_j/10.js对象.html">
            
                
                    <a href="../../home/JavaScript_j/10.js对象.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        js对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="home/JavaScript_j/11.js数组.html">
            
                
                    <a href="../../home/JavaScript_j/11.js数组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        js数组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="home/JavaScript_j/12.js数学对象Math.html">
            
                
                    <a href="../../home/JavaScript_j/12.js数学对象Math.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        js数学对象Math
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="home/JavaScript_j/13.js正则.html">
            
                
                    <a href="../../home/JavaScript_j/13.js正则.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        js正则
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="home/jQuery_j/jQuery.html">
            
                
                    <a href="../../home/jQuery_j/jQuery.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        jQuery
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="home/jQuery_j/1.jquery选择器.html">
            
                
                    <a href="../../home/jQuery_j/1.jquery选择器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        jquery选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="home/jQuery_j/2.jQuery元素操作.html">
            
                
                    <a href="../../home/jQuery_j/2.jQuery元素操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        jQuery元素操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="home/jQuery_j/3.相关尺寸.html">
            
                
                    <a href="../../home/jQuery_j/3.相关尺寸.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        相关尺寸
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="home/jQuery_j/4.jQuery事件.html">
            
                
                    <a href="../../home/jQuery_j/4.jQuery事件.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        jQuery事件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="home/jQuery_j/5.jquery元素节点操作.html">
            
                
                    <a href="../../home/jQuery_j/5.jquery元素节点操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        jquery元素节点操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="5" data-path="home/AJAX/AJAX.html">
            
                
                    <a href="../../home/AJAX/AJAX.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        AJAX
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6" data-path="home/VUE/vue.html">
            
                
                    <a href="../../home/VUE/vue.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        VUE
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="home/VUE/1.创建第一个vue实例.html">
            
                
                    <a href="../../home/VUE/1.创建第一个vue实例.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        创建第一个vue实例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="home/VUE/2.模版语法和基本指令.html">
            
                
                    <a href="../../home/VUE/2.模版语法和基本指令.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        模版语法和基本指令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="home/VUE/3.Vue中的计算属性和侦听器.html">
            
                
                    <a href="../../home/VUE/3.Vue中的计算属性和侦听器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        Vue中的计算属性和侦听器
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Introduction</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="ajax&#x662F;&#x4EC0;&#x4E48;">ajax&#x662F;&#x4EC0;&#x4E48;?</h1>
<hr>
<p><strong>AJAX &#x662F;&#x4E0E;&#x670D;&#x52A1;&#x5668;&#x4EA4;&#x6362;&#x6570;&#x636E;&#x5E76;&#x66F4;&#x65B0;&#x90E8;&#x5206;&#x7F51;&#x9875;&#x7684;&#x827A;&#x672F;&#xFF0C;&#x5728;&#x4E0D;&#x91CD;&#x65B0;&#x52A0;&#x8F7D;&#x6574;&#x4E2A;&#x9875;&#x9762;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x3002;</strong></p>
<blockquote>
<p>AJAX &#x6307;&#x5F02;&#x6B65; JavaScript &#x53CA; XML&#xFF08;Asynchronous JavaScript And XML&#xFF09;&#x3002;</p>
<p>AJAX &#x662F;&#x4E00;&#x79CD;&#x5728; 2005 &#x5E74;&#x7531; Google &#x63A8;&#x5E7F;&#x5F00;&#x6765;&#x7684;&#x7F16;&#x7A0B;&#x6A21;&#x5F0F;&#x3002;</p>
<p>AJAX &#x4E0D;&#x662F;&#x4E00;&#x79CD;&#x65B0;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#xFF0C;&#x800C;&#x662F;&#x4E00;&#x79CD;&#x4F7F;&#x7528;&#x73B0;&#x6709;&#x6807;&#x51C6;&#x7684;&#x65B0;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x901A;&#x8FC7; AJAX&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x66F4;&#x597D;&#x3001;&#x66F4;&#x5FEB;&#x4EE5;&#x53CA;&#x66F4;&#x53CB;&#x597D;&#x7684; WEB &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x3002;</p>
<p>AJAX &#x57FA;&#x4E8E; JavaScript &#x548C; HTTP &#x8BF7;&#x6C42;&#xFF08;HTTP requests&#xFF09;&#x3002;</p>
</blockquote>
<p><strong>&#x901A;&#x8FC7; HTTP &#x8BF7;&#x6C42;&#x52A0;&#x8F7D;&#x8FDC;&#x7A0B;&#x6570;&#x636E;</strong></p>
<p><strong>jQuery &#x5E95;&#x5C42;&#x5BF9; AJAX &#x5B9E;&#x73B0;&#x8FDB;&#x884C;&#x4E86;&#x5C01;&#x88C5;.&#x4F7F;&#x5F97;&#x6211;&#x4EEC;&#x5728;&#x8FDB;&#x884C;ajax&#x64CD;&#x4F5C;&#x65F6;,&#x4E0D;&#x5FC5;&#x50CF;&#x539F;&#x751F;js&#x4E2D;&#x90A3;&#x4E48;&#x590D;&#x6742;</strong></p>
<p><strong><code>$.get</code>, <code>$.post</code>, <code>$.ajax()</code> &#x8FD4;&#x56DE;&#x5176;&#x521B;&#x5EFA;&#x7684; XMLHttpRequest &#x5BF9;&#x8C61;&#x3002;&#x591A;&#x6570;&#x60C5;&#x51B5;&#x4E0B;&#x6211;&#x4EEC;&#x4E0D;&#x9700;&#x8981;&#x53BB;&#x64CD;&#x4F5C;&#x8FD4;&#x56DE;&#x7684;&#x5BF9;&#x8C61;</strong></p>
<ul>
<li><h3 id="&#x5982;&#x4F55;&#x4F7F;&#x7528;ajax&#x6280;&#x672F;">&#x5982;&#x4F55;&#x4F7F;&#x7528;ajax&#x6280;&#x672F;?</h3>
<blockquote>
<p>&#x9996;&#x5148;&#x4F60;&#x5F97;&#x6709;web&#x670D;&#x52A1;&#x5668;,&#x80FD;&#x591F;&#x901A;&#x8FC7;&#x6D4F;&#x89C8;&#x5668;&#x53BB;&#x6267;&#x884C;&#x4F60;&#x7684;html&#x548C;&#x4F60;&#x7684;python</p>
<p>&#x6CE8;&#x610F;&#x4E00;&#x70B9;:&#x6211;&#x4EEC;&#x5E73;&#x5E38;&#x5199;&#x7684;html,&#x76F4;&#x63A5;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x6253;&#x5F00;&#x65F6; &#x4F7F;&#x7528;&#x7684;&#x662F;file&#x534F;&#x8BAE;
&#x800C;ajax&#x662F;&#x57FA;&#x4E8E;HTTP&#x8BF7;&#x6C42;&#x7684;,&#x6240;&#x4EE5;&#x8981;&#x6C42;&#x4F60;&#x7684;html&#x80FD;&#x591F;&#x4F7F;&#x7528;http&#x7684;&#x534F;&#x8BAE;&#x6253;&#x5F00;
&#x5982;&#x679C;&#x4F60;&#x80FD;&#x505A;&#x5230;&#x7528;http&#x534F;&#x8BAE;&#x53BB;&#x6253;&#x5F00;&#x4F60;&#x7684;html&#x5E76;&#x4E14;&#x80FD;&#x591F;&#x6B63;&#x5E38;&#x663E;&#x793A;&#x7684;&#x8BDD;,&#x5C31;&#x4EE3;&#x8868;&#x4F60;&#x7684;web&#x670D;&#x52A1;&#x5668;&#x642D;&#x5EFA;&#x6210;&#x529F;</p>
</blockquote>
<ul>
<li><h5 id="get-&#x65B9;&#x6CD5;">$.get() &#x65B9;&#x6CD5;:</h5>
<pre><code class="lang-js">  <span class="hljs-comment">//&#x53D1;&#x9001;ajax&#x8BF7;&#x6C42; 1.url  2.&#x53EF;&#x9009; &#x53D1;&#x9001;get&#x8BF7;&#x6C42;&#x65F6;&#x643A;&#x5E26;&#x7684;&#x53C2;&#x6570;  ,3,&#x53EF;&#x9009; &#x56DE;&#x8C03;&#x51FD;&#x6570;,&#x8BF7;&#x6C42;&#x5B8C;&#x4E4B;&#x540E;&#x505A;&#x4EC0;&#x4E48;&#x4E8B;  4,&#x53EF;&#x9009;,&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; json</span>

  $.get(url,{&#x8BF7;&#x6C42;&#x7684;&#x53C2;&#x6570;},<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>)</span>{},<span class="hljs-string">&apos;json&apos;</span>)
</code></pre>
</li>
<li><h5 id="post">$.post()</h5>
<pre><code class="lang-js">  $.post(url,{&#x8BF7;&#x6C42;&#x7684;&#x53C2;&#x6570;},<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>)</span>{},<span class="hljs-string">&apos;json&apos;</span>)
</code></pre>
</li>
<li><h5 id="ajax">$.ajax()</h5>
<pre><code class="lang-js">  $.ajax({
      url:<span class="hljs-string">&apos;/cgi-bin/5.py&apos;</span>,<span class="hljs-comment">//&#x5F53;&#x524D;&#x8BF7;&#x6C42;&#x7684;url&#x5730;&#x5740;</span>
      type:<span class="hljs-string">&apos;get&apos;</span>,<span class="hljs-comment">//&#x5F53;&#x524D;&#x8BF7;&#x6C42;&#x7684;&#x65B9;&#x5F0F; get  post</span>
      data:{id:<span class="hljs-number">100</span>,username:<span class="hljs-string">&apos;zhangsan&apos;</span>},<span class="hljs-comment">//&#x8BF7;&#x6C42;&#x65F6;&#x53D1;&#x9001;&#x7684;&#x53C2;&#x6570;</span>
      dataType:<span class="hljs-string">&apos;json&apos;</span>,<span class="hljs-comment">//&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;</span>
      success:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>)</span>{
          <span class="hljs-comment">//ajax&#x8BF7;&#x6C42;&#x6210;&#x529F;&#x540E;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;</span>
          <span class="hljs-built_in">console</span>.log(data);
      },
      error:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
          <span class="hljs-comment">//ajax&#x6267;&#x884C;&#x5931;&#x8D25;&#x540E;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;</span>
          alert(<span class="hljs-string">&apos;ajax&#x6267;&#x884C;&#x9519;&#x8BEF;&apos;</span>);
      },
      timeout:<span class="hljs-number">2000</span>,<span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x5F53;&#x524D;&#x8BF7;&#x6C42;&#x7684;&#x8D85;&#x65F6;&#x65F6;&#x95F4;  &#x6BEB;&#x79D2;,&#x5FC5;&#x987B;&#x65F6;&#x5F02;&#x6B65;&#x8BF7;&#x6C42;&#x624D;&#x4F1A;&#x751F;&#x6548;</span>
      <span class="hljs-keyword">async</span>:<span class="hljs-literal">true</span><span class="hljs-comment">// &#x662F;&#x5426;&#x5F02;&#x6B65;  true&#x4E3A;&#x5F02;&#x6B65;  false &#x540C;&#x6B65;</span>
  })
</code></pre>
</li>
</ul>
</li>
<li><h3 id="ajax&#x5F02;&#x6B65;-&#x540C;&#x6B65;">ajax&#x5F02;&#x6B65; &#x540C;&#x6B65;</h3>
<pre><code class="lang-js">  <span class="hljs-comment">//&#x8BBE;&#x7F6E;ajax&#x7684;&#x5168;&#x5C40;&#x914D;&#x7F6E;  async:false &#x8BBE;&#x7F6E;&#x5F53;&#x524D;&#x8BF7;&#x6C42;&#x4E3A;&#x540C;&#x6B65;</span>
  $.ajaxSetup({
      <span class="hljs-keyword">async</span>:<span class="hljs-literal">false</span>
  })

  &#x5173;&#x4E8E;ajax&#x4E2D; &#x5F02;&#x6B65; &#x548C; &#x540C;&#x6B65; 

  ajax&#x9ED8;&#x8BA4;&#x5C31;&#x662F;&#x5F02;&#x6B65;&#x8BF7;&#x6C42;,

  <span class="hljs-keyword">async</span> (&#x9ED8;&#x8BA4;: <span class="hljs-literal">true</span>) &#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;&#x4E0B;&#xFF0C;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#x5747;&#x4E3A;&#x5F02;&#x6B65;&#x8BF7;&#x6C42;&#x3002;
  &#x5982;&#x679C;&#x9700;&#x8981;&#x53D1;&#x9001;&#x540C;&#x6B65;&#x8BF7;&#x6C42;&#xFF0C;&#x8BF7;&#x5C06;&#x6B64;&#x9009;&#x9879;&#x8BBE;&#x7F6E;&#x4E3A; <span class="hljs-literal">false</span>&#x3002;

  &#x540C;&#x6B65;&#x8BF7;&#x6C42;,&#x5C31;&#x53D1;ajax&#x8BF7;&#x6C42;&#x53D1;&#x51FA;&#x53BB;&#x540E;&#x5FC5;&#x987B;&#x7B49;&#x5F85;ajax&#x7684;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;&#x540E;&#x624D;&#x80FD;&#x7EE7;&#x7EED;&#x5F80;&#x4E0B;&#x6267;&#x884C;

  &#x4E00;&#x822C;&#x60C5;&#x51B5;&#x4E0B;&#x90FD;&#x4F7F;&#x7528;&#x5F02;&#x6B65;&#x64CD;&#x4F5C;&#x5C31;&#x53EF;&#x4EE5;,&#x9664;&#x975E;&#x6709;&#x7279;&#x6B8A;&#x60C5;&#x51B5;,&#x5FC5;&#x987B;&#x7B49;ajax&#x7684;&#x7ED3;&#x679C;&#x56DE;&#x6765;&#x540E;&#x624D;&#x80FD;&#x505A;&#x5904;&#x7406;&#x7684;,&#x5C31;&#x7528;&#x540C;&#x6B65;
</code></pre>
</li>
<li><h3 id="&#x6CE8;&#x610F;">&#x6CE8;&#x610F;</h3>
<pre><code class="lang-js">  <span class="hljs-number">1.</span>ajax&#x662F;&#x65E0;&#x5237;&#x65B0;&#x8BF7;&#x6C42;&#x670D;&#x52A1;&#x5668;,&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x662F;&#x611F;&#x89C9;&#x4E0D;&#x5230;,&#x4E5F;&#x770B;&#x4E0D;&#x5230;ajax&#x7684;&#x5177;&#x4F53;&#x8BF7;&#x6C42;&#x548C;&#x6267;&#x884C;&#x60C5;&#x51B5;&#x7684;.,
      &#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x501F;&#x52A9;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x8C03;&#x8BD5;&#x5DE5;&#x5177; (F12&#x6253;&#x5F00;) &#x8FDB;&#x884C;&#x67E5;&#x770B;

  <span class="hljs-number">2.</span>ajax&#x7684;&#x8BF7;&#x6C42;&#x662F;&#x57FA;&#x7840;HTTP&#x534F;&#x8BAE;&#x7684;,&#x5C31;&#x8981;&#x6C42;&#x4F60;&#x5F53;&#x524D;&#x6253;&#x5F00;&#x8FD9;&#x4E2A;&#x5E26;&#x6709;ajax&#x7684;html&#x65F6;&#x5FC5;&#x987B;&#x4F7F;&#x7528;http&#x534F;&#x8BAE;

  <span class="hljs-number">3.</span>ajax&#x8981;&#x6C42;&#x540C;&#x6E90;&#x7B56;&#x7565;
      http:<span class="hljs-comment">//127.0.0.1:8000/cgi-bin/1.py</span>
      &#x5373;: &#x534F;&#x8BAE;(http https)  &#x57DF;&#x540D;&#x6216;IP &#x4EE5;&#x53CA;&#x7AEF;&#x53E3;(<span class="hljs-number">80</span> <span class="hljs-number">443</span> <span class="hljs-number">8000</span> <span class="hljs-number">8080</span> ...)&#x90FD;&#x5FC5;&#x987B;&#x4E00;&#x81F4;

  <span class="hljs-number">4.</span>&#x5173;&#x4E8E;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; &#x5728;get() post() ajax() &#x90FD;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; <span class="hljs-string">&apos;json&apos;</span>
      &#x5982;&#x679C;&#x8981;&#x6C42;&#x8FD4;&#x56DE;json&#x683C;&#x5F0F;&#x6570;&#x636E;,&#x90A3;&#x4E48;&#x5C31;&#x5FC5;&#x987B;&#x8FD4;&#x56DE;json,&#x5982;&#x679C;&#x4E0D;&#x6B63;&#x786E;,
      &#x5728;get&#x548C;post&#x65B9;&#x6CD5;&#x5C06;&#x62FF;&#x4E0D;&#x5230;data&#x4E2D;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;,&#x5728;ajax&#x65B9;&#x6CD5;&#x4E2D;&#x5219;&#x4F1A;&#x8FDB;&#x53BB;error&#x65B9;&#x6CD5;

  <span class="hljs-number">5.</span>&#x5728;python&#x4E2D;&#x8FD4;&#x56DE;json&#x683C;&#x5F0F;&#x6570;&#x636E;,
      &#x5F15;&#x5165; json&#x6A21;&#x5757;
      json.dumps(&#x6570;&#x636E;)  &#x4F7F;&#x7528;json_dumps&#x65B9;&#x6CD5;&#x8FDB;&#x884C;json&#x683C;&#x5F0F;&#x7684;&#x7F16;&#x7801;&#x8F6C;&#x6362;

  <span class="hljs-number">6.</span>&#x5728;&#x4F7F;&#x7528;ajax&#x65B9;&#x6CD5;&#x65F6;.&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61; XMLHttpRequest
      &#x90A3;&#x4E48;&#x5728;ajax&#x7684;&#x65B9;&#x6CD5;&#x4E2D;&#x4F7F;&#x7528;&#x7684; $(<span class="hljs-keyword">this</span>) &#x5C31;&#x4EE3;&#x8868; ajax&#x7684;&#x5BF9;&#x8C61;

      $(<span class="hljs-keyword">this</span>) &#x6C38;&#x8FDC;&#x4EE3;&#x8868;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;,&#x6CA1;&#x6709;&#x6307;&#x660E;&#x5BF9;&#x8C61;&#x65F6; &#x4EE3;&#x8868;&#x7684;&#x65F6;<span class="hljs-built_in">window</span>&#x5BF9;&#x8C61;,
      &#x5728;&#x5B83;&#x6709;&#x5BF9;&#x8C61;&#x65F6; &#x4EE3;&#x8868;&#x7684;&#x5C31;&#x662F;&#x5F53;&#x524D;&#x7684;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;
</code></pre>
</li>
<li><h3 id="&#x4E86;&#x89E3;json&#x683C;&#x5F0F;&#x6570;&#x636E;">&#x4E86;&#x89E3;json&#x683C;&#x5F0F;&#x6570;&#x636E;</h3>
<p>  json&#x662F; JavaScript Object Notation &#x7684;&#x9996;&#x5B57;&#x6BCD;&#x7F29;&#x5199;&#xFF0C;&#x5355;&#x8BCD;&#x7684;&#x610F;&#x601D;&#x662F;javascript&#x5BF9;&#x8C61;&#x8868;&#x793A;&#x6CD5;&#xFF0C;&#x8FD9;&#x91CC;&#x8BF4;&#x7684;json&#x6307;&#x7684;&#x662F;&#x7C7B;&#x4F3C;&#x4E8E;javascript&#x5BF9;&#x8C61;&#x7684;&#x4E00;&#x79CD;&#x6570;&#x636E;&#x683C;&#x5F0F;&#xFF0C;&#x76EE;&#x524D;&#x8FD9;&#x79CD;&#x6570;&#x636E;&#x683C;&#x5F0F;&#x6BD4;&#x8F83;&#x6D41;&#x884C;&#xFF0C;&#x9010;&#x6E10;&#x66FF;&#x6362;&#x6389;&#x4E86;&#x4F20;&#x7EDF;&#x7684;xml&#x6570;&#x636E;&#x683C;&#x5F0F;&#x3002;</p>
<p>  javascript&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#xFF1A;</p>
<pre><code class="lang-js">  <span class="hljs-keyword">var</span> tom = {
      name:<span class="hljs-string">&apos;tom&apos;</span>,
      age:<span class="hljs-number">18</span>
  }
</code></pre>
<p>  json&#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;&#xFF1A;</p>
<pre><code class="lang-js">  {
      <span class="hljs-string">&quot;name&quot;</span>:<span class="hljs-string">&apos;tom&apos;</span>,
      <span class="hljs-string">&quot;age&quot;</span>:<span class="hljs-number">18</span>
  }
</code></pre>
<p>  &#x4E0E;json&#x5BF9;&#x8C61;&#x4E0D;&#x540C;&#x7684;&#x662F;&#xFF0C;json&#x6570;&#x636E;&#x683C;&#x5F0F;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x79F0;&#x9700;&#x8981;&#x7528;&#x53CC;&#x5F15;&#x53F7;&#x5F15;&#x8D77;&#x6765;&#xFF0C;&#x7528;&#x5355;&#x5F15;&#x53F7;&#x6216;&#x8005;&#x4E0D;&#x7528;&#x5F15;&#x53F7;&#x4F1A;&#x5BFC;&#x81F4;&#x8BFB;&#x53D6;&#x6570;&#x636E;&#x9519;&#x8BEF;&#x3002;</p>
<p>  json&#x7684;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x683C;&#x5F0F;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x548C;javascript&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x5B57;&#x9762;&#x91CF;&#x76F8;&#x540C;&#x3002;</p>
<pre><code class="lang-js">  [<span class="hljs-string">&apos;tom&apos;</span>,<span class="hljs-number">18</span>,<span class="hljs-string">&apos;programmer&apos;</span>]
</code></pre>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/jQuery_j/5.jquery元素节点操作.html" class="navigation navigation-prev " aria-label="Previous page: jquery元素节点操作"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/VUE/vue.html" class="navigation navigation-next " aria-label="Next page: VUE"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
